package com.ssy.lingxi.system.controller;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.PageModel;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.system.dto.request.CommonIdDTO;
import com.ssy.lingxi.system.entity.ShopConfig;
import com.ssy.lingxi.system.model.dto.common.CommonStateDTO;
import com.ssy.lingxi.system.model.dto.shop.AddShopDTO;
import com.ssy.lingxi.system.model.dto.shop.SiteIdAndTemplateIdDTO;
import com.ssy.lingxi.system.model.dto.shop.UpdateShopDTO;
import com.ssy.lingxi.system.service.ShopConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 基础设置 - 商城设置
 * @author fhj
 * @version 2.0.0
 * @date 2020/7/20
 */
@RestController
@RequestMapping("/shop")
public class ShopConfigController {

    @Resource
    private ShopConfigService shopConfigService;
    @Resource
    private HttpServletRequest request;

    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public Wrapper<PageData<ShopConfig>> list(PageModel dto) {
        return shopConfigService.list(dto);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/details")
    public Wrapper<ShopConfig> details(CommonIdDTO dto) {
        return shopConfigService.details(dto);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Wrapper<Void> add(@RequestBody @Valid AddShopDTO dto) {
        return shopConfigService.add(request, dto);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Wrapper<Void> update(@RequestBody @Valid UpdateShopDTO dto) {
        return shopConfigService.update(request, dto);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public Wrapper<Void> delete(@RequestBody @Valid CommonIdDTO dto) {
        return shopConfigService.delete(dto);
    }

    @ApiOperation(value = "停用/启用")
    @PostMapping("/stop/start")
    public Wrapper<Void> stopAndStart(@RequestBody @Valid CommonStateDTO dto) {
        return shopConfigService.stopAndStart(request, dto);
    }

    @ApiOperation(value = "所有")
    @GetMapping("/all")
    public Wrapper<List<ShopConfig>> all() {
        return shopConfigService.all();
    }

    @ApiOperation(value = "根据站点和模板获取所有商城")
    @GetMapping("/allBySiteAndTemplate")
    public Wrapper<List<ShopConfig>> allBySiteAndTemplate(@Valid SiteIdAndTemplateIdDTO dto) {
        return shopConfigService.allBySiteAndTemplate(dto);
    }
}
